$(function() {
	//1、列表（分页）
	getListPost();
	//2、下载
	$(document).on('click', '._downloadReport', function() {
			var id = $(this).attr('idNum');
			
			var postData = {
				id: id
			};
			formSubmit({
				url: '/download/fetch.html',
				data: postData,
				type: 'post'
			});
		})
		//--------函数-------------------------
	function getListPost(postdata) {
		var default_data = {
			page: 1
		};
		postdata = $.extend({}, default_data, postdata);
		$.post('/userReport/ajaxReportList.html', postdata, callbackFuc);
	}

	function callbackFuc(data) {
		//console.log(data);
		if(data.status == 200) {
			var html = template('_boughtReportModel', data.data);
			$('#_boughtReportList').html(html);
		}
		//分页
		if(data.data.totalpage != 1) {
			$('#_curPage').pagination({
				pageCount: data.data.totalpage,
				current: data.data.page,
				coping: true,
				callback: function(data) {
					$.post('/userReport/ajaxReportList.html', {
						page: data.getCurrent()
					}, callbackFuc);
				}
			});
		} else {
			$('#_curPage').html('');
		}
	}
	//模拟表单提交
	function formSubmit(data) {
		var formInnHTML = ['<form style="display:none" action="' + (data.url || '#') + '" method="' + (data.type || 'post') + '">']
		for(var k in data.data) {
			formInnHTML.push('<input type="text" name="' + k + '" value="' + data.data[k] + '" />');
		}
		formInnHTML.push('<input type="submit" /></form>');
		var submitFrom = $(formInnHTML.join(''))[0];
		//	console.log(submitFrom);
		$('body').append(submitFrom);
		submitFrom.submit();
	}
})